from pypatnlp import *

# load the corpora
pycorp = PyCorpus('hinnavaatlus.pycorp', readonly=True)
corp = read_corpus_from_file('hinnavaatlus.corp')
ner_pycorp = PyCorpus('../../data/estner.pycorp', readonly=True)
ner_corp = read_corpus_from_file('estner.corp')

# mine frequent patterns around adjectives
adj_cov = regex_cover(pycorp, 'wtype', 'A')
back_cov = regex_cover(ner_pycorp, 'wtype', 'A')
miner = HrAprioriMiner(radius=2, size_limit=2, treshold=0.025,
                       background=ner_corp, background_cover=back_cov,
                       significance_treshold=0.025)
miner.fit(corp, adj_cov)

# compute covers for frequent rules and print HTML file that emphasizes
# the matched positions of the frequent rules
frequent_rules = miner.get_frequent()
covers = conjunction_covers(frequent_rules, basic_rule_covers(corp, 2))
full_cover = reduce(lambda x, y: x | y, covers)
html = cover_html(pycorp, 'word', full_cover)
open('output.html', 'w').write(html.encode('utf-8'))


